<template>
	<view class="page">
		<view class="search-title">
			<view class="search-title-left" @click="visableChange">
				<view class="search-title-left-item">
					{{dateList}}
				</view>
				<uni-icons type="calendar"  v-show='iconShow' size="36rpx"></uni-icons>
			</view>
			<view class="search-title-right" @click="inputDialogToggle()">
				<view class="search-title-right-item">
					{{workList}}
				</view>
				<uni-icons type="list"  size="36rpx"></uni-icons>
			</view>
			<view>
				<!-- 输入框示例 -->
				<uni-popup ref="inputDialog" type="dialog">
					<uni-popup-dialog ref="inputClose"  mode="input" title="报工人" :value="createPeo" 
						placeholder="请输入报工人姓名" @confirm="dialogInputConfirm"></uni-popup-dialog>
				</uni-popup>
			</view>
		</view>
		<view class='bg-grey'>
			<view class='time-flex' v-if="visible">
				<view class='time-flex-item' @click="selectTime(0)">
					<view class='time-flex-item-padding'>今天</view>
				</view>
				<view class='time-flex-item' @click="selectTime(1)">
					<view class='time-flex-item-padding'>昨天</view>
				</view>
				<view class='time-flex-item' @click="selectTime(2)">
					<view class='time-flex-item-padding'>本月</view>
				</view>
				<view class='time-flex-item' @click="selectTime(3)">
					<view class='time-flex-item-padding'>上月</view>
				</view>
				<view class='time-flex-item' @click="selectTime(4)">
					<view class='time-flex-item-padding'>全部</view>
				</view>
				<view class='time-flex-item' @click="selectTime(5)">
					<view class='time-flex-item-padding'>选择时间</view>
				</view>
			</view>
			<view class="conf-list">
				<view class="conf-list-item" v-for="(item,index) in listData" :key="index">
					<view class="conf-list-card">
						<view class="conf-list-title">
							<view>
								{{item.maktx}}
							</view>
							<view>
								{{item.matnr}}
							</view>
						</view>
						
						<view class="conf-list-content1">
							<view>
								<text>指令单：</text>
								<text>{{item.aufnr}}</text>
							</view>
							<view>
								<text>工序名称：</text>
								<text>{{item.ltxa1Name}}</text>
							</view>
						</view>
						<view class="conf-list-content1">
							<view>
								<text>颜色：</text>
								<text>{{item.color_dictText}}</text>
							</view>
							<view>
								<text>尺码：</text>
								<text>{{item.size}}</text>
							</view>
							
						</view>
						<view class="conf-list-content1">
							<view>
								<text>合格数：</text>
								<text>{{item.gmnga}}</text>
							</view>
							<view>
								<text>不合格数量：</text>
								<text>{{item.xmnga}}</text>
							</view>
						</view>
						<view class="conf-list-content">
							<text>报工日期：</text>
							<text>{{item.budat}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-calendar ref="calendar" class="uni-calendar--hook" :clear-date="true" :date="info.date"
			:insert="info.insert" :lunar="info.lunar" :startDate="info.startDate" :endDate="info.endDate"
			:range="info.range" @confirm="confirm" @close="close" />

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState(['companyCode'])
		},
		data() {
			return {
				dateSel:'5',
				selType:'2',
				visible: false,
				dateBegin: '',
				dateEnd: '',
				employees: '',
				iconShow: true,
				showCalendar: false,
				info: {
					lunar: true,
					range: true,
					insert: false,
					selected: []
				},

				badRate: '1.2%',
				confirmationString: '135/26966',
				dateList: '日期',
				workList: '筛选',
				searchText: '',
				value: 2,
				range: [{
						value: 2,
						text: "工序单"
					},
					{
						value: 1,
						text: "产品"
					},
					{
						value: 3,
						text: "工序"
					},
				],
				text: '暂无数据',
				title: '下拉刷新 + 加载更多',
				data: [],
				listData: [],
				pageNo: 0,
				endFlag: false,
				filter: "",
				loadMoreText: "加载中...",
				showLoadMore: false,
				selFlag: false,
				inputText: "",
				aufnr: '',
				matnr: '',
				vornr: '',
				beginDate: '',
				endDate: '',
				createBy: '',
				view: false,
				date: '',
				checked: true,
				createPeo:''
			};
		},

		onShow() {
			this.createBy = uni.getStorageSync('login_user_info').username
			this.loadMoreText = "加载更多";
		},
		onLoad(e) {
				this.initData();
		},
		mounted(){
		},
		onUnload() {
			this.max = 0;
			// this.data = [],
			this.listData = [];
		},
		onReachBottom() {
			if (this.endFlag == true) {
				this.loadMoreText = "已显示全部数据"
				uni.showToast({
					icon: 'none',
					title: this.loadMoreText
				});
				return;
			}
			setTimeout(() => {
				this.listData = []
				this.getList()
			}, 300);
		},
		onPullDownRefresh() {
			this.pageNo = 0,
			
			this.selType= 2,
			this.selContext= '',
			this.aufnr =''
			this.value=2;
			this.dateSel=5,
			this.employees= '',
			this.dateBegin= '',
			this.dateEnd='',
			// this.createBy = ''
			// this.aufnr = ''
			// this.matnr = ''
			// this.vornr = ''
			// this.beginDate = ''
			// this.endDate = ''
			// this.checked = false
			this.initData();
			uni.stopPullDownRefresh();
		},
		methods: {
			visableChange() {
				console.log('点击本月', this.visible)
				this.visible = !this.visible
			},
			choose() {
				this.selFlag = true;
				console.log(this.selFlag,'shuju123')
				// let bgVO={baogong:baogong,index:index}

			},
			inputDialogToggle() {
				this.$refs.inputDialog.open()
			},
			dialogClose() {
				console.log('点击关闭')
			},
			dialogInputConfirm(val) {
				this.pageNo = 0;
				console.log("========");
				this.createBy = val;
				this.getList()
				// 关闭窗口后
				this.$refs.inputDialog.close()
				// 清空文本
				this.$refs.inputClose.val = '';
			},
			close() {
				console.log('弹窗关闭');
			},
			confirm(e) {
				console.log('confirm 返回:', e.range.after, e.range.before)
				this.iconShow = false
				this.dateList = e.range.before + "~" + e.range.after
				this.dateSel = 6
				this.beginDate = e.range.before
				this.endDate = e.range.after
				this.pageNo = 0;
				this.getList()
			},
			//选择时间
			selectTime(index) {
				this.pageNo = 0;
				this.endFlag = false;
				switch (index) {
					case 0:
						this.dateList = '今天'
						this.dateSel = 1
						this.iconShow = true
						break;
					case 1:
						this.dateList = '昨天'
						this.dateSel = 2
						this.iconShow = true
						break;
					case 2:
						this.dateList = '本月'
						this.dateSel = 3
						this.iconShow = true
						break;
					case 3:
						this.dateList = '上月'
						this.dateSel = 4
						this.iconShow = true
						break;
					case 4:
						this.dateList = '全部'
						this.dateSel = 5
						this.iconShow = true
						break;
					default:
						this.$refs.calendar.open()
						break;
				}
				
				if(index!=5){
					this.getList()
				}
			setTimeout(() => {
				this.visible = !this.visible
			}, 300);
				
			},
			
			scanCode() {
				let that = this;
				uni.scanCode({
					success: function(res) {
						that.searchText = res.result;
						that.aufnr = res.result;
										that.pageNo = 0;
										that.selType='2';
										that.value=2
						let e = {};
						e.detail = {};
						e.detail.value = res.result;
						that.onInput(e);
					}
				});
			},
			change(e) {
				this.selType = e
				console.log("e:", e);
			},
			
			beginDateChange(e) {
				this.beginDate = e.detail.value
				this.pageNo = 0;
				this.getList()
			},
			endDateChange(e) {
				this.endDate = e.detail.value
				this.pageNo = 0;
				this.getList()
			},
			checkboxChange: function(e) {
				if (e.detail.value.length !== 0) {
					this.createBy = uni.getStorageSync('login_user_info').username
					this.checked = !this.checked
				} else {
					this.createBy = ''
					this.checked = !this.checked
				}
			},
			dropDown() {
				this.view = !this.view
				console.log('this.view===>' + this.view)
			},
			search() {
				this.pageNo = 1;
				this.getList()
				this.view = !this.view
				// this.listData=[];
				// this.loadData();
			},
			
			onInput(e) {
				console.log(e.detail.value,'工序单号')
				this.aufnr = e.detail.value
				this.getList()
			},
			onInputAufnr(e) {
				console.log(e.detail.value)
				this.aufnr = e.detail.value
				this.pageNo = 0;
				this.getList()
			},
			onInputMatnr(e) {
				console.log(e.detail.value)
				this.matnr = e.detail.value
				this.pageNo = 0;
				this.getList()
			},
			onInputVornr(e) {
				console.log(e.detail.value)
				this.vornr = e.detail.value
				this.pageNo = 0;
				this.getList()
			},

			initData() {
				setTimeout(() => {
					this.getList();
					uni.stopPullDownRefresh();
				}, 300);
			},
           //产品列表
			getList() {
				this.listData=[]
				let url = '/dcloud/confirmation/confirmation/confirmationList'
				this.pageNo+=1
				this.$http.get(url, {
					params: {
						"pageNo":this.pageNo,
						"pageSize":100,
						"aufnr":this.aufnr,
						"dateSel": this.dateSel,
						"matnrSearch":this.matnr,
						"vornrSearch":this.vornr,
						"beginDate":this.beginDate,
						"endDate":this.endDate,
						"createBy":this.createBy,
					}
				}).then(res => {
					if (res.data.success) {
						const data = res.data.result
						this.confirmationString = data.afruCount + '/' + data.afruNum;
						this.listData=res.data.result.records;
						if (this.listData.length <100) {
						
							this.endFlag = true;
							this.loadMoreText = "已显示全部数据"
						}
					}
				}).catch(err => {
					console.log(err);
				});
			},
			postSearch(e) {
				this.listData = [];
				this.endFlag = false;
				this.pageNo = 1;
				this.filter = e.detail.value;
				this.loadMoreText = "加载更多",
					this.getList();
			},
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-select {
		font-size: 14px;
		border: 0px solid #dd524d;
		box-sizing: border-box;
		border-radius: 0px;
		padding: 0 5px;
		padding-left: 10px;
		position: relative;
		display: flex;
		-webkit-user-select: none;
		user-select: none;
		flex-direction: row;
		align-items: center;
		/*    border-bottom: solid 1px #e5e5e5; */
		border-left: solid 1px #e5e5e5;
		width: 100%;
		flex: 1;
		height: 50upx;
	}

	::v-deep .uni-stat__actived {
		width: 150rpx;
		flex: 1;
	}

	page {
		background: #FFFFFF;
		width: 750upx;
		overflow-x: hidden;
	}

	.search-title {
		display: flex;
		padding: 5upx 0upx;

		.search-title-left {
			flex: 1;
			height: 60upx;
			display: flex;
			justify-content: center;
			border-right: solid 1px #e5e5e5;

			.search-title-left-item {
				font-size: 32upx;
				line-height: 62upx;
				// margin-right: 15upx;
			}
		}
		.search-title-left:active{
			background-color: #f5f5f5;
		}

		.search-title-right {
			flex: 1;
			height: 60upx;
			display: flex;
			justify-content: center;
			.search-title-right-item {
				font-size: 32upx;
				line-height: 62upx;
				margin-right: 15upx;
			}
		}
		.search-title-right:acitve{
			background-color: #f5f5f5;
		}
	}

	.bg-grey {
		background-color: rgb(234, 231, 231);
		padding: 2upx 20upx;

		.time-flex {
			display: flex;
			flex-wrap: wrap;

			.time-flex-item {
				width: 50%;
				text-align: center;
				height: 100upx;
				padding: 10upx 30upx;

				.time-flex-item-padding {
					background: #FFFFFF;
					height: 80upx;
					color: black;
					border-radius: 14upx;
					line-height: 80upx;
				}
				.time-flex-item-padding:active {
						background-color: #f5f5f5;
					}
			}
		}

		.search-list {

			display: flex;
			height: 140upx;
			padding: 10upx 0upx 10upx 0upx;

			.search-list-left {
				flex: 1;
				text-align: center;
				padding-right: 20upx;
				height: 120upx;

				.search-list-left-padding {

					background: rgb(146, 212, 2);
					border-radius: 14upx;
					height: 120upx;
					padding: 10upx 0upx;
				}
			}

			.search-list-right {
				flex: 1;
				text-align: center;
				padding-left: 20upx;
				height: 120upx;

				.search-list-right-padding {
					background: #34A4DF;
					border-radius: 14upx;
					height: 120upx;
					padding: 10upx 0upx;
				}

			}
		}

		.conf-list {
			margin-top: -10upx;

			// 	height: 180upx;
			// background: greeen;
	// 		.conf-list-item:active {	// 	background-color: #f5f5f5;	// }
			.conf-list-item {
				height: 300upx;
				background: #FFFFFF;
				color: black;
				border-radius: 20upx;

				.conf-list-card {
					height: 300upx;
					border-radius: 20upx;
					margin-top: 20upx;

					.conf-list-title {
						height: 60upx;

						display: flex;
						padding: 6upx 20upx 0 20upx;
						justify-content: space-between;
						border-radius: 20upx 20upx 0upx 0upx;
						border-bottom: solid 1px #e5e5e5;
						font-size: 30upx;
						// padding: 10upx 0 0 0;
						// line-height: 30upx;
					}

					.conf-list-content {
						height: 60upx;
						padding: 0 20upx;
						font-size: 26upx;
					}

					.conf-list-content1 {
						height: 60upx;
						padding: 0 20upx;
						font-size: 26upx;
						display: flex;
						justify-content: space-between;
						view{
							font-size: 26upx;
						}
					}
				}
			}
		}
	}


	.header {
		display: flex;
		flex-direction: row;
		padding: 10px 15px;
		align-items: center;
		/* background-color: #b6bbc3; */
		background-image: linear-gradient(#34A4DF, #34A4DF, #2bace7);
	}

	.shaixuan {
		/* display: flex; */
		/* background-color: #a8acb4; */
		background-image: linear-gradient(#2bace7, #64c7fc, #8edffc);
		height: 400rpx;
		flex-direction: column;
	}

	.picker {
		color: #000;
	}

	.nopicker {
		color: #8d8d8d;
	}

	.input-view {
		display: flex;
		align-items: center;
		flex-direction: row;
		background-color: #fff;
		height: 60upx;
		border-radius: 30upx;
		padding: 0 20upx;
		flex: 1;
	}

	.input-view2 {
		display: flex;
		align-items: center;
		flex-direction: row;
		background-color: #fff;
		height: 30px;
		border-radius: 15px;
		padding: 0 10px;
		margin: 0px 15px 10px;
		width: 86%;
	}

	.input {
		flex: 2;
		padding: 0 5px;
		height: 24px;
		line-height: 24px;
		font-size: 16px;
		color: #000;
	}

	.icon {
		display: flex;
		flex-direction: column;
		justify-content: center;
		margin-left: 10px;
	}

	.bottom {
		position: fixed;
		bottom: 90upx;
		right: 50upx;
		width: 90upx;
		height: 90upx;
	}

	.uni-media-list-text-top {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.uni-media-list-text-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		color: #8f8f94;
		line-height: 26upx;
	}

	/* #ifdef APP-PLUS ||MP-WEIXIN */
	checkbox .wx-checkbox-input {
		/* border: #00AAFF solid 1rpx; */
	}

	checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		background: #ff8c08 !important;
		/* border: #00AAFF solid 1rpx; */

	}

	.wx-checkbox-input {
		border: none !important;
	}

	.wx-checkbox-input.wx-checkbox-input-checked {
		border: none !important;
	}

	/* #endif */

	.empty {
		width: 100%;
		display: flex;
		flex-direction: column;
		height: auto;
		margin-top: 220rpx;
		margin-bottom: 200rpx;
		background-color: #FFFFFF;

	}

	.img {
		margin-bottom: 0;
		width: 160rpx;
		height: 160rpx;
	}
</style>
